package tree.ordertraversal;

import tree.TreeNode;

/**
 * @Classname : FlattenBinaryTreeToLinkedList
 * @Description : 114. 二叉树展开为链表
 * https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/
 * @Author : cty
 * @Date 2023/3/30 21:36
 */


public class FlattenBinaryTreeToLinkedList {
    private TreeNode cur;

    public void flatten(TreeNode root) {
        cur = new TreeNode();
        preorder(root);
    }

    private void preorder(TreeNode root) {
        if (root == null) return;

        cur.right = root;
        cur.left = null;
        cur = root;
        TreeNode right = root.right;

        preorder(root.left);
        preorder(right);
    }
}
